<template>
  <div class="test-pdf-page">
    <div class="test-container">
      <h1>PDF导出功能测试</h1>
      
      <div class="test-content">
        <h2>测试内容</h2>
        <p>这是一个测试页面，用于验证PDF导出功能是否正常工作。</p>
        
        <div class="test-resume" ref="testResume">
          <div class="resume-header">
            <h1>张三</h1>
            <div class="contact-info">
              <p>电话: 13800138000</p>
              <p>邮箱: zhangsan@example.com</p>
              <p>籍贯: 北京</p>
            </div>
          </div>
          
          <div class="resume-section">
            <h2>工作经历</h2>
            <div class="experience-item">
              <h3>前端开发工程师</h3>
              <p>某科技公司 | 2022-2024</p>
              <p>负责前端开发工作，使用Vue.js和React技术栈。</p>
            </div>
          </div>
          
          <div class="resume-section">
            <h2>教育背景</h2>
            <div class="education-item">
              <h3>计算机科学与技术 - 本科</h3>
              <p>北京大学 | 2018-2022</p>
            </div>
          </div>
        </div>
        
        <div class="test-buttons">
          <button @click="testExport" :disabled="exporting" class="export-btn">
            {{ exporting ? '导出中...' : '测试导出PDF' }}
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { usePdfExport } from '~/composables/usePdfExport'

const { exportToPdf } = usePdfExport()
const exporting = ref(false)
const testResume = ref<HTMLElement>()

const testExport = async () => {
  try {
    exporting.value = true
    
    if (!testResume.value) {
      throw new Error('找不到测试内容')
    }
    
    await exportToPdf(testResume.value, {
      filename: 'test-resume.pdf',
      quality: 0.98,
      scale: 2,
      backgroundColor: '#ffffff'
    })
    
    console.log('测试PDF导出成功')
  } catch (error) {
    console.error('测试PDF导出失败:', error)
    alert('PDF导出失败，请重试')
  } finally {
    exporting.value = false
  }
}
</script>

<style scoped>
.test-pdf-page {
  min-height: 100vh;
  background-color: #f5f5f5;
  padding: 20px;
}

.test-container {
  max-width: 800px;
  margin: 0 auto;
  background: white;
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.test-content h1 {
  color: #333;
  margin-bottom: 20px;
}

.test-content h2 {
  color: #1890ff;
  margin: 20px 0 10px 0;
}

.test-resume {
  background: white;
  padding: 30px;
  margin: 20px 0;
  border: 1px solid #e8e8e8;
  border-radius: 4px;
  font-family: 'Microsoft YaHei', sans-serif;
  line-height: 1.6;
}

.resume-header {
  text-align: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 2px solid #1890ff;
}

.resume-header h1 {
  font-size: 28px;
  font-weight: bold;
  color: #333;
  margin: 0 0 15px 0;
}

.contact-info p {
  margin: 5px 0;
  color: #666;
}

.resume-section {
  margin-bottom: 25px;
}

.resume-section h2 {
  font-size: 18px;
  font-weight: bold;
  color: #333;
  margin-bottom: 15px;
  padding-bottom: 8px;
  border-bottom: 1px solid #e8e8e8;
}

.experience-item,
.education-item {
  margin-bottom: 15px;
}

.experience-item h3,
.education-item h3 {
  font-size: 16px;
  font-weight: 600;
  color: #333;
  margin: 0 0 5px 0;
}

.experience-item p,
.education-item p {
  color: #666;
  margin: 2px 0;
}

.test-buttons {
  text-align: center;
  margin-top: 30px;
}

.export-btn {
  background: #722ed1;
  color: white;
  border: none;
  border-radius: 4px;
  padding: 12px 24px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s;
}

.export-btn:hover:not(:disabled) {
  background: #9254de;
}

.export-btn:disabled {
  background: #d9d9d9;
  cursor: not-allowed;
}
</style>
